package com.oreilly.ez.web;


import com.oreilly.ez.base.R;
import com.oreilly.ez.entity.Amtf;
import com.oreilly.ez.repo.AmtfRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/amtfs")
@Validated
public class AmtfCtrl extends BaseCtrl<Amtf> {

    @Autowired
    private AmtfRepo amtfRepo;

    @Override
    public Object find(Amtf amtf, Pageable pageable) {
        return amtfRepo.findAll(Sort.by(Sort.Order.desc("udate")));
    }

    @Override
    public Object findOne(@PathVariable Integer id) {
        return amtfRepo.findById(id);
    }

    @Override
    public Object save(@RequestBody  @Valid Amtf amtf) {
        return amtfRepo.save(amtf);
    }

    @Override
    public Object delete(@PathVariable Integer id) {
         amtfRepo.deleteById(id);
         return R.ok("delete ok");
    }
}
